﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Courseware : System.Web.UI.Page
{
    db_courseware cw = new db_courseware();
    db_course course = new db_course();
    public string coursewareName = "";
    public string coursewareAbout = "";
    public string coursewareUtime = "";
    public string coursewareUrl = "";
    public string coursewarePic = "";
    public string teach = "";
    public string courseId = "";
    public string courseName = "";
    public string coursewareID = "";

    public bool isLogin = false; //是否登录
    public bool isSell = false; //是否购买

    public string strcr = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null)
        {
            Response.Redirect("index.aspx");
        }
        db_blogroll blogroll = new db_blogroll();
        DataSet ds_blogroll = blogroll.selectBlogrollALL();
        blogrollList.DataSource = ds_blogroll.Tables[0].DefaultView;
        blogrollList.DataBind();

        db_copyright cr = new db_copyright();
        DataSet dscr = cr.selectOne();
        strcr = "Copyright &copy; " + dscr.Tables[0].Rows[0]["cryear"].ToString() + " " + dscr.Tables[0].Rows[0]["owner"].ToString() + " ALL Rights Reserved<br/><a href=\"http://www.miibeian.gov.cn\" target=\"_blank\">" + dscr.Tables[0].Rows[0]["approve"].ToString() + "</a>";

        DataSet hit = new DataSet();

        hit = course.selectCourseSellTop("8");
        all_hit_list.DataSource = hit.Tables[0].DefaultView;
        all_hit_list.DataBind();

        
        DataSet ds = new DataSet();
        coursewareID = Request.QueryString["id"];

        string stuid = "";
        //判断是否登录
        try
        {
            if (Session["stuId"] != null)
            {
                isLogin = true;
                stuid = Session["stuId"].ToString();
            }
            else
            {
                isLogin = false;
            }
        }
        catch
        {
            isLogin = false;
        }

        //判读是否购买
        if (isLogin)
        {
            
            ds = cw.selectCoursewareByCourseID(coursewareID);
            if (ds.Tables[0].Rows.Count == 0)
            {
                Response.Write("<script language=javascript>alert('找不到数据！');</script>");
                Response.End();
            }
            else
            {
                isSell = course.CourseisSell(stuid, ds.Tables[0].Rows[0]["courseId"].ToString());
                //如果购买就显示课件下载地址
                if (isSell)
                {
                    coursewareName = ds.Tables[0].Rows[0]["coursewareName"].ToString();
                    coursewareAbout = ds.Tables[0].Rows[0]["about"].ToString();
                    coursewareUtime = ds.Tables[0].Rows[0]["uploadTime"].ToString();
                    coursewareUrl = ds.Tables[0].Rows[0]["coursewareUrl"].ToString();
                    coursewarePic = ds.Tables[0].Rows[0]["picUrl"].ToString();
                    teach = ds.Tables[0].Rows[0]["teacherId"].ToString();
                    courseName = ds.Tables[0].Rows[0]["courseName"].ToString();
                    courseId = ds.Tables[0].Rows[0]["courseId"].ToString();
                    this.Page.Title = coursewareName + "_" + courseName + "_课件信息 - 三剑客在线教育系统";
                }
                else
                {
                    Response.Write("<script language=javascript>alert('请购买相应的课程后再尝试！');</script>");
                    Response.End();
                }
            }
        }
        else
        {
            Response.Write("<script language=javascript>alert('请登录后再尝试');</script>");
            Response.End();
        }
    }
}